<script>
    /* 
        1.完整写法
        let {key2:变量2,key1:变量1,...} = {key1:"值1",key2"值2",...};
        将当前key对应的值，赋值给当前变量  将值1赋值给变量1  将值2赋值给变量2

        2.简写 (键和变量名相同直接写变量名)
        let {变量1,变量2,...} = {key1:"值1",key2"值2",...};
    */

    // 1.完整写法
   let {name:name1,sex:sex1,age:age1} = {name:"孙悟空",age:18,sex:"猴"};
   console.log(name1,sex1,age1);

   //2.简写 (键和变量名相同直接写变量名)
    //let {uname:uname,usex:usex,uage:uage} = {uname:"猪八戒",uage:100,usex:"猪"};
   let {uname,usex,uage} = {uname:"猪八戒",uage:100,usex:"猪"};
   console.log(uname,usex,uage);


    //3.解构失败 (值是undefined)
    let person = {
        name:"战三",
        age:100
    };

    // let {name,age,sex} = person;
    // console.log(name,age,sex);  //战三 100 undefined  
    
    // 4.解构默认值
    let {name,age,sex="男"} = person;
    console.log(name,age,sex);  //战三 100 undefined  

</script>